layui.use(['util', 'jquery', 'jquery_dotdotdot_min_js', 'laypage'], function () {
    var util = layui.util,
        $ = layui.jquery;

    laypage.render({
        elem: 'pagination',
        limit: 9,
        jump: function (obj, first) {

        }
    });

    //Top header显示控制
    var is, timer, dom = $(document), fixedHeader = $('.jsFixedHeader');
    var scroll = function () {
        var stop = dom.scrollTop();
        if (stop >= 200) {
            is || (fixedHeader.show(), is = 1);
        } else {
            is && (fixedHeader.hide(), is = 0);
        }
    };
    dom.on('scroll', function () {
        clearTimeout(timer);
        timer = setTimeout(function () {
            scroll();
        }, 100);
    });

    $(document).ready(function () {
        clearTimeout(timer);
        timer = setTimeout(function () {
            scroll();
        }, 100);

        if($(".user_name").length){
            $(".user_name").dotdotdot({
                height: 20,
                fallbackToLetter: true,
                watch: true,
            });
        }
    });
});

//获取url后面的参数
function getQueryString(name, num) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = num ? decodeURI(window.location.search).substr(1).match(reg) : window.location.search.substr(1).match(reg);
    if(r != null) {
        return unescape(r[2]);
    }
    return null;
}


/**
 * 动态修改url多个参数
 * @param url 地址
 * @param obj 要变更的参数对象{arg:arg_val, arg1:arg_val1}
 */
function changeURLArgs(obj, url) {
    url = url ? url : this.location.href.toString();
    // console.log('url', url);
    // console.log('obj', obj);
    for (var arg in obj){
        var arg_val = obj[arg];
        var pattern = arg + '=([^&]*)';
        var replaceText = arg + '=' + arg_val;
        if (url.match(pattern)) {
            var tmp = '/(' + arg + '=)([^&]*)/gi';
            tmp = url.replace(eval(tmp), replaceText);
            url = tmp;
        } else {
            if (url.match('[\?]')) {
                var tmp = url + '&' + replaceText;
                url = tmp;
            } else {
                var tmp = url + '?' + replaceText;
                url = tmp;
            }
        }
    }
    // console.log('url', url);
    window.location.href = url;
    return url;
}